package com.alks.function.mapper.chengKong;

import com.alks.entity.data.entity.*;
import com.alks.function.data.dto.chengKong.assort.*;
import com.alks.function.data.request.chengKong.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface RAndDUsageMapper {

    /**
     * 查询型体配色资料
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("select STYLE_NO,COLOR_CODE,STYLE_COLOR,PHOTO_PATH from YF_STYLE_COLOR_DETAIL where STYLE_NO=#{styleNo} " +
            "and STYLE_COLOR=#{styleColor}")
    YfStyleColorDetail getStyleColorDetail(@Param("styleNo") String styleNo,
                                           @Param("styleColor") String styleColor);

    /**
     * 查询检验状态
     * @param styleNo
     * @return
     */
    @Select("select STYLE_NO,CFM_FLAG,BASE_SIZE from YF_STYLE where STYLE_NO=#{styleNo}")
    YfStyle getStyle(String styleNo);

    /**
     * 查询是否已经存在
     * @param styleNo
     * @param styleColor
     */
    @Select({
            "<script>",
            "SELECT STYLE_NO FROM YF_BOM_HEAD_NEW2",
            "WHERE  STYLE_NO = #{styleNo}",
            "AND STYLE_COLOR  = #{styleColor}",
            "</script>"
    })
    String getStyleUsage(@Param("styleNo") String styleNo,
                         @Param("styleColor") String styleColor);

    /**
     * 查询是否已检验
     * @param styleNo
     * @param styleColor
     */
    @Select("select CFM_FLAG from YF_BOM_HEAD_NEW2 where STYLE_NO = #{styleNo} and STYLE_COLOR  = #{styleColor}")
    String checkout(@Param("styleNo") String styleNo,
                    @Param("styleColor") String styleColor);

    /**
     * 新增
     * @param yfBomHeadNew2
     */
    @Insert("insert into YF_BOM_HEAD_NEW2(COMPANY_ID,STYLE_NO,STYLE_COLOR,SYS_USER,SYS_DATE,BASE_SIZE,COLOR_CODE)values " +
            "(#{companyId},#{styleNo},#{styleColor},#{sysUser},#{sysDate},#{baseSize},#{colorCode})")
    void addStyleUsage(YfBomHeadNew2 yfBomHeadNew2);

    /**
     * 删除型体颜色资料输入
     * @param styleNo
     * @param styleColor
     */
    @Delete("delete from YF_BOM_PART_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void delStyleUsageDetail(@Param("styleNo") String styleNo,
                             @Param("styleColor") String styleColor);

    /**
     * 新增
     * @param list
     */
    @Insert({
            "<script>",
            "insert into YF_BOM_PART_NEW2(COMPANY_ID,STYLE_NO,STYLE_COLOR,SEQ_NO,PART_NAME,SEGMENT,MTL_NO,MTL_NAME,MTL_COLOR,MTL_SPEC,MTL_UNIT,`USAGE`,USAGE_TYPE" +
                    ",VENDOR,SIZE1,SIZE2,MTL_TYPE_NO,MTL_NO2,DRAW_DEPT,MTL_PROPERTY,NO_LOT_USAGE,SIZE_TYPE,REMARK,STYLE_COPY_TEMP,COLOR_COPY_TEMP)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.companyId},#{item.styleNo},#{item.styleColor},#{item.seqNo},#{item.partName},#{item.segment},#{item.mtlNo},#{item.mtlName},#{item.mtlColor}," +
            "#{item.mtlSpec},#{item.mtlUnit},#{item.usage},#{item.usageType},#{item.vendor},#{item.size1},#{item.size2},#{item.mtlTypeNo},#{item.mtlNo2},#{item.drawDept}," +
            "#{item.mtlProperty},#{item.noLotUsage},#{item.sizeType},#{item.remark},#{item.styleCopyTemp},#{item.colorCopyTemp})",
            "</foreach>",
            "</script>"
    })
    void addStyleUsageDetail(@Param("list") List<YfBomPartNew2> list);

    /**
     * 新增
     * @param list
     */
    @Insert({
            "<script>",
            "insert into YF_BOM_PART_NEW2_BAK(COMPANY_ID,STYLE_NO,STYLE_COLOR,SEQ_NO,PART_NAME,SEGMENT,MTL_NO,MTL_NAME,MTL_COLOR,MTL_SPEC,MTL_UNIT,`USAGE`,USAGE_TYPE" +
                    ",VENDOR,SIZE1,SIZE2,MTL_TYPE_NO,MTL_NO2,DRAW_DEPT,MTL_PROPERTY,NO_LOT_USAGE,SIZE_TYPE,REMARK,STYLE_COPY_TEMP,COLOR_COPY_TEMP)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.companyId},#{item.styleNo},#{item.styleColor},#{item.seqNo},#{item.partName},#{item.segment},#{item.mtlNo},#{item.mtlName},#{item.mtlColor}," +
                    "#{item.mtlSpec},#{item.mtlUnit},#{item.usage},#{item.usageType},#{item.vendor},#{item.size1},#{item.size2},#{item.mtlTypeNo},#{item.mtlNo2},#{item.drawDept}," +
                    "#{item.mtlProperty},#{item.noLotUsage},#{item.sizeType},#{item.remark},#{item.styleCopyTemp},#{item.colorCopyTemp})",
            "</foreach>",
            "</script>"
    })
    void addStyleUsageDetailBak(@Param("list") List<YfBomPartNew2> list);

    /**
     * 删除日志数据
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Delete("delete from YF_BOM_PART_NEW2_BAK where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    int delYfBomPartNew2Bak(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor);

    /**
     * 添加日志操作
     * @param changes
     */
    @Insert({
            "<script>",
            "INSERT INTO YF_BOM_CHANGE (COMPANY_ID, STYLE_NO, STYLE_COLOR, PART_NAME, SEGMENT, CHANGE_TYPE, REMARK, SYS_DATE, SYS_USER) VALUES ",
            "<foreach collection='list' item='t' separator=','>",
            "(#{t.companyId}, #{t.styleNo}, #{t.styleColor}, #{t.partName}, #{t.segment}, #{t.changeType}, #{t.remark}, #{t.sysDate}, #{t.sysUser})",
            "</foreach>",
            "</script>"
    })
    void addYfBomChangeList(@Param("list") List<YfBomChange> changes);

    /**
     * 单个添加
     * @param yfBomPartNew2
     */
    @Insert("insert into YF_BOM_PART_NEW2(COMPANY_ID,STYLE_NO,STYLE_COLOR,SEQ_NO,PART_NAME,SEGMENT,MTL_NO,MTL_NAME,MTL_COLOR,MTL_SPEC,MTL_UNIT,`USAGE`,USAGE_TYPE" +
            ",VENDOR,SIZE1,SIZE2,MTL_TYPE_NO,MTL_NO2,DRAW_DEPT,MTL_PROPERTY,NO_LOT_USAGE,SIZE_TYPE,REMARK,STYLE_COPY_TEMP,COLOR_COPY_TEMP) values "+
            "(#{companyId},#{styleNo},#{styleColor},#{seqNo},#{partName},#{segment},#{mtlNo},#{mtlName},#{mtlColor},#{mtlSpec},#{mtlUnit},#{usage},#{usageType}," +
            "#{vendor},#{size1},#{size2},#{mtlTypeNo},#{mtlNo2},#{drawDept},#{mtlProperty},#{noLotUsage},#{sizeType},#{remark},#{styleCopyTemp},#{colorCopyTemp})")
    void addStyleUsageDetail2(YfBomPartNew2 yfBomPartNew2);
    /**
     * 检验0/1取消检验
     * @param userName
     * @param now
     * @param cfmFlag
     * @param styleNo
     * @param styleColor
     */
    @Update("update YF_BOM_HEAD_NEW2 set CFM_FLAG=#{cfmFlag}, CFM_USER=#{userName}, CFM_DATE=#{now} where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void updateCheckOutFlag(@Param("userName") String userName,
                            @Param("now") LocalDateTime now,
                            @Param("cfmFlag") String cfmFlag,
                            @Param("styleNo")String styleNo,
                            @Param("styleColor")String styleColor);

    /**
     * 注意事项列表
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("select SEQ_NO,SEQ_NAME,PROD_MEMO from YF_BOM_MEMO_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} order by SEQ_NO")
    List<YfBomMemoNew2Dto> getPrecautionsForFiling(@Param("styleNo")String styleNo,
                                                   @Param("styleColor")String styleColor);

    /**
     * 注意事项建档
     * @param yfBomMemoNew2List
     */
    @Insert({
            "<script>",
            "insert into YF_BOM_MEMO_NEW2(COMPANY_ID,STYLE_NO,STYLE_COLOR,SEQ_NO,PROD_MEMO,SEQ_NAME)",
            "values ",
            "<foreach collection='yfBomMemoNew2List' item='item' separator=','>",
            "(#{item.companyId},#{item.styleNo},#{item.styleColor},#{item.seqNo},#{item.prodMemo},#{item.seqName})",
            "</foreach>",
            "</script>"
    })
    void addPrecautionsForFiling(@Param("yfBomMemoNew2List") List<YfBomMemoNew2> yfBomMemoNew2List);

    /**
     * 删除注意事项
     * @param styleNo
     * @param styleColor
     */
    @Delete("delete from YF_BOM_MEMO_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void delPrecautionsForFiling(@Param("styleNo")String styleNo,
                                 @Param("styleColor")String styleColor);

    /**
     * 查询型体颜色材料
     * @param newStyleNo
     * @param newStyleColor
     */
    @Select("SELECT STYLE_NO from YF_BOM_PART_NEW2 where STYLE_NO=#{newStyleNo} and STYLE_COLOR=#{newStyleColor} limit 1")
    String getStyleColorMaterial(@Param("newStyleNo")String newStyleNo,
                                 @Param("newStyleColor") String newStyleColor);

    /**
     * 型体颜色材料输入列表
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("SELECT * from YF_BOM_PART_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} order by SEQ_NO")
    List<YfBomPartNew2> getStyleColorMaterialList(@Param("styleNo")String styleNo,
                                                  @Param("styleColor")String styleColor);

    /**
     * 型体颜色bom资料日志表
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("SELECT * from YF_BOM_PART_NEW2_BAK where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} order by SEQ_NO")
    List<YfBomPartNew2> getStyleColorMaterialList2(@Param("styleNo")String styleNo,
                                                  @Param("styleColor")String styleColor);

    /**
     * 删除型体打勾记录
     * @param styleNo
     * @param styleColor
     * @param seqNoList
     */
    @Delete({
            "<script>",
            "delete from YF_BOM_PART_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} and SEQ_NO IN",
            "<foreach collection='seqNoList' item='seqNo' separator=',' open='(' close=')'>",
            "#{seqNo}",
            "</foreach>",
            "</script>"
    })
    void deleteTickRecords(@Param("styleNo")String styleNo,
                           @Param("styleColor")String styleColor,
                           @Param("seqNoList") List<BigDecimal> seqNoList);

    /**
     * 删除型体建档
     * @param styleNo
     * @param styleColor
     */
    @Delete("delete from YF_BOM_HEAD_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void delTypeFiling(@Param("styleNo")String styleNo,
                       @Param("styleColor")String styleColor);
    /**
     * 删除全码资料(list)
     * @param styleNo
     * @param styleColor
     */
    @Delete("delete from YF_BOM_USAGE_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void delFullCodeDetailList(@Param("styleNo")String styleNo,
                           @Param("styleColor")String styleColor);

    /**
     * 新增
     * @param list
     */
    @Insert({
            "<script>",
            "insert into YF_BOM_USAGE_NEW2(COMPANY_ID,STYLE_NO,STYLE_COLOR,PART_NAME,SEGMENT,MTL_NO,USAGE_TYPE,SIZE_FROM," +
                    "SIZE_TO,MTL_USAGE,SEQ_NO)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.companyId},#{item.styleNo},#{item.styleColor},#{item.partName},#{item.segment},#{item.mtlNo},#{item.usageType}," +
                    "#{item.sizeFrom},#{item.sizeTo},#{item.mtlUsage},#{item.seqNo})",
            "</foreach>",
            "</script>"
    })
    void addFullCodeDetail(@Param("list") List<YfBomUsageNew2> list);

    /**
     * 删除全码用量资料
     * @param styleNo
     * @param styleColor
     * @param list
     */
    @Delete({
            "<script>",
            "<foreach collection='list' item='t' separator=';'>",
            "delete from YF_BOM_USAGE_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} ",
            "and PART_NAME=#{t.partName} and SEGMENT=#{t.segment} and SIZE_FROM=#{t.sizeFrom}",
            "</foreach>",
            "</script>",
    })
    void delFullCodeDetail(@Param("styleNo")String styleNo,
                           @Param("styleColor")String styleColor,
                           @Param("list") List<FullCodeRequest> list);

    /**
     * 型体颜色用量明细查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT a.STYLE_NO,a.STYLE_COLOR,t.TYPE_NAME,a.SEQ_NO,a.PART_NAME,a.SEGMENT,a.mtlNo,a.MTL_NAME,a.MTL_COLOR,a.MTL_SPEC,a.MTL_UNIT,",
            "a.SIZE1,a.SIZE2,a.VENDOR,a.`USAGE`,a.USAGE_TYPE,a.DRAW_DEPT,a.SIZE_TYPE,a.MTL_PROPERTY,a.NO_LOT_USAGE,a.REMARK from ",
            "(SELECT STYLE_NO,STYLE_COLOR,SEQ_NO,PART_NAME,SEGMENT,MTL_NO2 as mtlNo,MTL_NAME,MTL_COLOR,MTL_SPEC,MTL_UNIT,SIZE1,SIZE2,VENDOR,"+
            "`USAGE`,USAGE_TYPE,DRAW_DEPT,SIZE_TYPE,MTL_PROPERTY,NO_LOT_USAGE,REMARK,SUBSTRING( MTL_NO2, 1, 2 ) AS typeNo from YF_BOM_PART_NEW2) a",
            " LEFT JOIN YF_MTL_TYPE_NEW t ON a.typeNo = t.TYPE_NO ",
            "<where>",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "AND a.STYLE_NO like concat('%',#{styleNo},'%')",
            "</if>",
            "<if test='styleColor != null and !styleColor.isEmpty()'>",
            "AND a.STYLE_COLOR like concat('%',#{styleColor},'%')",
            "</if>",
            "<if test='mtlName != null and !mtlName.isEmpty()'>",
            "AND a.MTL_NAME like concat('%',#{mtlName},'%') ",
            "</if>",
            "<if test='mtlColor != null and !mtlColor.isEmpty()'>",
            "AND a.MTL_COLOR like concat('%',#{mtlColor},'%') ",
            "</if>",
            "<if test='partName != null and !partName.isEmpty()'>",
            "AND a.PART_NAME like concat('%',#{partName},'%')",
            "</if>",
            "<if test='typeName != null and !typeName.isEmpty()'>",
            "AND t.TYPE_NAME = #{typeName}",
            "</if>",
            "</where>",
            "ORDER BY a.SEQ_NO asc",
            "</script>"
    })
    List<YfBomPartNew2Dto> getUsageDetailsQuery(UsageDetailsQueryRequest request);

    /**
     * 根据部位段序号修改型体颜色资料
     * @param yfBomPartNew2
     */
    @Update("update YF_BOM_PART_NEW2 set  PART_NAME=#{partName},MTL_NO=#{mtlNo},MTL_NAME=#{mtlName},MTL_COLOR=#{mtlColor}," +
            "MTL_SPEC=#{mtlSpec},MTL_UNIT=#{mtlUnit},VENDOR=#{vendor},MTL_NO2=#{mtlNo2},USAGE_TYPE=#{usageType},DRAW_DEPT=#{drawDept}," +
            "SIZE_TYPE=#{sizeType},MTL_PROPERTY=#{mtlProperty} where STYLE_NO=#{styleNo}" +
            "and STYLE_COLOR=#{styleColor} and SEQ_NO=#{seqNo}")
    void UpdateStyleUsageDetailBySegment(YfBomPartNew2 yfBomPartNew2);

    /**
     * 全码用量资料列表
     * @param request
     * @return
     */
    @Select("select COMPANY_ID,STYLE_NO,STYLE_COLOR,PART_NAME,SEGMENT,SIZE_FROM,MTL_USAGE from YF_BOM_USAGE_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} and PART_NAME=#{partName}" +
            " and SEGMENT=#{segment}")
    List<YfBomUsageNew2> getFullCodeDetailRenewList(FullCodeRenewGetRequest request);

    /**
     * 查询用量变更记录
     * @param request
     * @return
     */
    @Select("select PART_NAME,SEGMENT,CHANGE_TYPE,REMARK,SYS_DATE,SYS_USER from YF_BOM_CHANGE where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor} order by SYS_DATE desc")
    List<YfBomChangeDto> getUsageDetailsChangeQuery(UsageDetailsQueryChangeRequest request);

    /**
     * 型体查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "select STYLE_NO from YF_BOM_HEAD_NEW2",
            "<where>",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "AND STYLE_NO LIKE CONCAT('%',#{styleNo},'%')",
            "</if>",
            "<if test='styleColor != null and !styleColor.isEmpty()'>",
            "AND STYLE_COLOR LIKE CONCAT('%',#{styleColor},'%')",
            "</if>",
            "<if test='colorCode != null and !colorCode.isEmpty()'>",
            "AND AND COLOR_CODE LIKE CONCAT('%',#{colorCode},'%')",
            "</if>",
            "</where>",
            "group by STYLE_NO order by SYS_DATE desc ",
            "</script>",
    })
    List<String> getStyleQuery(UsageDetailsQueryChangeRequest request);

    /**
     * 型体颜色图片查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT a.STYLE_NO,a.STYLE_COLOR,a.COLOR_CODE,t.PHOTO_PATH,a.BASE_SIZE as remark,a.CFM_FLAG from(SELECT STYLE_NO,STYLE_COLOR,COLOR_CODE,CFM_FLAG,BASE_SIZE from YF_BOM_HEAD_NEW2 )a LEFT JOIN  ",
            "YF_STYLE_COLOR_DETAIL t on a.STYLE_NO=t.STYLE_NO and a.STYLE_COLOR=t.STYLE_COLOR",
            "<where>",
            "a.STYLE_NO = #{styleNo}",
            "<if test='styleColor != null and !styleColor.isEmpty()'>",
            "AND a.STYLE_COLOR = #{styleColor}",
            "</if>",
            "<if test='colorCode != null and !colorCode.isEmpty()'>",
            "AND a.COLOR_CODE = #{colorCode}",
            "</if>",
            "</where>",
            "</script>",
    })
    List<StyleToPhotoDto> getStyleToColorQuery(UsageDetailsQueryChangeRequest request);

    /**
     * 贴合子材料明细
     * @param mtlNo
     * @return
     */
    @Select("select SUB_MTL_NO as mtlNo,SUB_MTL_NAME as mtlName,SUB_MTL_COLOR as mtlColor,SUB_MTL_SPEC as mtlSpec,SUB_MTL_UNIT as mtlUnit,PRD_TYPE,PERCENT," +
            "PUR_FLAG,MTL_SEQ,VENDOR from YF_BOM_FIT_SUB where MTL_NO=#{mtlNo} order by MTL_SEQ asc")
    List<YfSubMtlTemp2Dto> getDetailsOfAdhesiveSubMaterials(String mtlNo);

    /**
     * 根据材料名称还原信息
     * @param mtlColor
     * @param mtlName
     * @param mtlSpec
     * @return
     */
    @Select({
            "<script>",
            "SELECT SUB_MTL_NO AS mtlNo, SUB_MTL_NAME AS mtlName, SUB_MTL_COLOR AS mtlColor,",
            "SUB_MTL_SPEC AS mtlSpec, SUB_MTL_UNIT AS mtlUnit, PRD_TYPE, PERCENT,",
            "PUR_FLAG, MTL_SEQ, VENDOR",
            "FROM YF_BOM_FIT_SUB",
            "WHERE MTL_COLOR = #{mtlColor} AND MTL_NAME = #{mtlName} and MTL_UNIT=#{mtlUnit}",
            "<if test='mtlSpec != null and !mtlSpec.isEmpty()'>",
            "AND MTL_SPEC = #{mtlSpec}",
            "</if>",
            "</script>"
    })
    List<YfSubMtlTemp2Dto> getDetailsOfAdhesiveSubMaterials2(@Param("mtlColor") String mtlColor, @Param("mtlName") String mtlName, @Param("mtlSpec") String mtlSpec,@Param("mtlUnit")String mtlUnit);

    /**
     * 贴合子材料查询
     * @param mtlNo
     * @param mtlSeq
     * @return
     */
    @Select("select * from YF_BOM_FIT_SUB where MTL_NO=#{mtlNo} and MTL_SEQ=#{mtlSeq}")
    YfBomFitSub getDetailsOfAdhesiveSubMaterial(@Param("mtlNo") String mtlNo,@Param("mtlSeq") String mtlSeq);

    /**
     * 修改请购
     *
     * @param mtlNo   物料编码
     * @param mtlSeq  序号
     * @param flag    状态
     * @param percent
     */
    @Update("update YF_BOM_FIT_SUB set PUR_FLAG=#{flag},PERCENT=#{percent} where MTL_NO=#{mtlNo} and MTL_SEQ=#{mtlSeq}")
    void UpdateDetailsOfAdhesiveSubMaterials(@Param("mtlNo")String mtlNo,
                                             @Param("mtlSeq")String mtlSeq,
                                             @Param("flag")String flag,
                                             @Param("percent") String percent);

    /**
     * 添加修改请购日志记录
     * @param subLog
     */
    @Insert("insert into YF_BOM_FIT_SUB_LOG(COMPANY_ID,MTL_NO,MTL_COLOR,MTL_NAME,MTL_SPEC,MTL_UNIT,SUB_MTL_NO,SUB_MTL_COLOR,SUB_MTL_NAME,SUB_MTL_SPEC," +
            "SUB_MTL_UNIT,PRD_TYPE,PERCENT,PUR_FLAG,SYS_USER,SYS_DATE,MTL_SEQ,REMARK) values (#{companyId},#{mtlNo},#{mtlColor},#{mtlName},#{mtlSpec}," +
            "#{mtlUnit},#{subMtlNo},#{subMtlColor},#{subMtlName},#{subMtlSpec},#{subMtlUnit},#{prdType},#{percent},#{purFlag},#{sysUser},#{sysDate},#{mtlSeq},#{remark})")
    void addDetailsOfAdhesiveSubMaterials(YfBomFitSubLog subLog);

    /**
     * 复制用量列表
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT t.STYLE_NO,t.STYLE_COLOR,MIN(a.CUT_SIZE) minCutSize,MAX(a.CUT_SIZE) maxCutSize,t.CFM_FLAG from (SELECT STYLE_NO,STYLE_COLOR,CFM_FLAG FROM " +
                    "YF_BOM_HEAD_NEW2)t LEFT JOIN YF_STYLE_SIZE a on t.STYLE_NO=a.STYLE_NO",
            "<where>",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "<if test='styleNo.equals(currentStyleNo)'>",
            "AND t.STYLE_NO LIKE CONCAT('%', #{styleNo}, '%')",
            "AND t.STYLE_COLOR != #{currentStyleColor}",
            "</if>",
            "<if test='!styleNo.equals(currentStyleNo)'>",
            "AND t.STYLE_NO != #{currentStyleNo}",
            "AND t.STYLE_COLOR != #{currentStyleNo}",
            "AND t.STYLE_NO LIKE CONCAT('%', #{styleNo}, '%')",
            "</if>",
            "</if>",
            "<if test='styleNo == null and styleNo.isEmpty()'>",
            "AND t.STYLE_NO != #{currentStyleNo}",
            "AND t.STYLE_COLOR != #{currentStyleColor}",
            "</if>",
            "</where>",
            "GROUP BY t.STYLE_NO,t.STYLE_COLOR",
            "</script>"
    })
    List<CopyingDosageListDto> getCopyingDosageList(CopyingDosageQueryRequest request);

    /**
     * 查询型体冲刀号
     * @param currentStyleNo
     * @return
     */
    @Select("SELECT CUT_SIZE from YF_STYLE_SIZE where STYLE_NO=#{currentStyleNo} order by SEQ_NO")
    List<String> getTypeSize(String currentStyleNo);

    /**
     * 修改型体颜色BOM用量
     * @param styleNo
     * @param styleColor
     * @param partName
     * @param segment
     * @param usage
     */
    @Update("update YF_BOM_PART_NEW2 set `USAGE`=#{usage} where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}" +
            "and PART_NAME=#{partName} and SEGMENT=#{segment}")
    void updateCopyingDosage(@Param("styleNo") String styleNo,
                             @Param("styleColor") String styleColor,
                             @Param("partName") String partName,
                             @Param("segment") String segment,
                             @Param("usage") BigDecimal usage);

    /**
     * 根据bom查询物料编码是否被使用
     * @param mtlNo
     */
    @Select("SELECT MTL_NO2 FROM YF_BOM_PART_NEW2 where MTL_NO2=#{mtlNo} GROUP BY MTL_NO2")
    String getBomByMtlNo(String mtlNo);

    /**
     * 修改颜色编码
     * @param styleNo
     * @param styleColor
     * @param colorCode
     */
    @Update("update YF_BOM_HEAD_NEW2 set COLOR_CODE=#{colorCode} where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    int updateBomColorCode(@Param("styleNo") String styleNo,
                           @Param("styleColor") String styleColor,
                           @Param("colorCode") String colorCode);

    /**
     * 根据型体颜色查询
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("SELECT count(1) from SD_BOM_HEAD_NEW2 where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    Integer getSdBomHeadNew2(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor);

    /**
     * 修改基本码
     * @param baseSize
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Update("update YF_BOM_HEAD_NEW2 set BASE_SIZE=#{baseSize} where STYLE_NO=#{styleNo} and STYLE_COLOR=#{styleColor}")
    int updateBaseSize(@Param("baseSize") String baseSize,
                       @Param("styleNo") String styleNo,
                       @Param("styleColor") String styleColor);
}
